﻿// Decompiled with JetBrains decompiler
// Type: StoryMode.StoryModePhases.ThirdPhase
// Assembly: StoryMode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 11BAE65F-6C15-4628-A9C6-1B968588CDA1
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\Modules\StoryMode\bin\Win64_Shipping_Client\StoryMode.dll

using StoryMode.GameComponents.CampaignBehaviors;
using System.Collections.Generic;
using TaleWorlds.ActivitySystem;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Library;
using TaleWorlds.SaveSystem;

#nullable disable
namespace StoryMode.StoryModePhases
{
  public class ThirdPhase
  {
    [SaveableField(1)]
    private readonly MBList<Kingdom> _oppositionKingdoms;
    [SaveableField(2)]
    private readonly MBList<Kingdom> _allyKingdoms;

    internal static void AutoGeneratedStaticCollectObjectsThirdPhase(
      object o,
      List<object> collectedObjects)
    {
      ((ThirdPhase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      collectedObjects.Add((object) this._oppositionKingdoms);
      collectedObjects.Add((object) this._allyKingdoms);
    }

    internal static object AutoGeneratedGetMemberValueIsCompleted(object o)
    {
      return (object) ((ThirdPhase) o).IsCompleted;
    }

    internal static object AutoGeneratedGetMemberValue_oppositionKingdoms(object o)
    {
      return (object) ((ThirdPhase) o)._oppositionKingdoms;
    }

    internal static object AutoGeneratedGetMemberValue_allyKingdoms(object o)
    {
      return (object) ((ThirdPhase) o)._allyKingdoms;
    }

    [SaveableProperty(3)]
    public bool IsCompleted { get; private set; }

    public MBReadOnlyList<Kingdom> OppositionKingdoms
    {
      get => (MBReadOnlyList<Kingdom>) this._oppositionKingdoms;
    }

    public MBReadOnlyList<Kingdom> AllyKingdoms => (MBReadOnlyList<Kingdom>) this._allyKingdoms;

    public ThirdPhase()
    {
      this._oppositionKingdoms = new MBList<Kingdom>();
      this._allyKingdoms = new MBList<Kingdom>();
      this.IsCompleted = false;
    }

    public void AddAllyKingdom(Kingdom kingdom) => this._allyKingdoms.Add(kingdom);

    public void AddOppositionKingdom(Kingdom kingdom) => this._oppositionKingdoms.Add(kingdom);

    public void RemoveOppositionKingdom(Kingdom kingdom)
    {
      this._oppositionKingdoms.Remove(kingdom);
    }

    public void CompleteThirdPhase(
      QuestBase.QuestCompleteDetails defeatTheConspiracyQuestCompleteDetail)
    {
      this.IsCompleted = true;
      switch (defeatTheConspiracyQuestCompleteDetail)
      {
        case QuestBase.QuestCompleteDetails.Invalid:
        case QuestBase.QuestCompleteDetails.Cancel:
        case QuestBase.QuestCompleteDetails.Timeout:
          ActivityManager.EndActivity("CompleteMainQuest", ActivityOutcome.Abandoned);
          break;
        case QuestBase.QuestCompleteDetails.Success:
          ActivityManager.EndActivity("CompleteMainQuest", ActivityOutcome.Completed);
          break;
        case QuestBase.QuestCompleteDetails.Fail:
        case QuestBase.QuestCompleteDetails.FailWithBetrayal:
          ActivityManager.EndActivity("CompleteMainQuest", ActivityOutcome.Failed);
          break;
      }
      Campaign.Current.CampaignBehaviorManager.RemoveBehavior<ThirdPhaseCampaignBehavior>();
    }
  }
}
